# coding: utf-8
import sys
import json

sys.path.append("..")
from raft.node_launcher import StaticNodeLauncher

if __name__ == '__main__':
    # 从配置文件和参数中获取信息
    print(sys.argv)
    with open('data/configure.json', 'r') as f:
        conf = json.load(f)
    conf['addr'] = tuple(conf['addr'])
    tuple_peers = dict()
    for x in conf['peers'].keys():
        tuple_peers[x] = (conf['peers'][x][0], conf['peers'][x][1])
    conf['peers'] = tuple_peers
    if len(sys.argv) == 2:
        conf['interval'] = float(sys.argv[1])
    else:
        conf['interval'] = float(10)

    # 构造launcher对象
    launcher = StaticNodeLauncher(conf)

    # 启动watcher和receiver功能
    launcher.start_resource_watching()
